package com.springboot.jdk.lock;

/**
 * @author: zr
 * @date: 2021-09-30
 */
public class ThreadLocalDemo {

    public static volatile int i = 0;

    private static ThreadLocal<Long> local = new ThreadLocal();

    public static void main(String[] args) {
        new Thread() {
            @Override
            public void run() {
                local.set(2L);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程1往ThreadLocal放置的数据是：" + local.get());
            }
        }.start();

        new Thread() {
            @Override
            public void run() {
                local.set(3L);
                System.out.println("线程2往ThreadLocal放置的数据是：" + local.get());
            }
        }.start();
    }
}
